package com.sphd.emanu.fragment.materialsclassify;

import android.content.Context;
import android.support.v7.app.AlertDialog;

import com.google.gson.JsonObject;
import com.sphd.emanu.mvp.BasePresenterImpl;
import com.wzutils.L;

import cn.pedant.SweetAlert.SweetAlertDialog;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * MVPPlugin
 *  邮箱 784787081@qq.com
 */

public class MaterialsclassifyPresenter extends BasePresenterImpl<MaterialsclassifyContract.View> implements MaterialsclassifyContract.Presenter{


    @Override
    public void deleteMaterialCategory(Integer categoryId, final int pos, final SweetAlertDialog sweetAlertDialog) {
        emanuService.deleteMaterialCategory(categoryId).enqueue(new Callback<JsonObject>() {
            @Override
            public void onResponse(Call<JsonObject> call, Response<JsonObject> response) {
                L.e(response.toString()+"---"+response.body().toString());
                mView.setDelRes(res(response),pos,sweetAlertDialog);
            }

            @Override
            public void onFailure(Call<JsonObject> call, Throwable t) {
                Error(t);
            }
        });
    }
    @Override
    public void updateMaterialCategory(int id, Integer level, String name, Integer oid, Integer paId, final Integer pos, final AlertDialog viewDialog) {
        emanuService.updateMaterialCategory(id,level,name,oid,paId).enqueue(new Callback<JsonObject>() {
            @Override
            public void onResponse(Call<JsonObject> call, Response<JsonObject> response) {
                mView.setAddRes(res(response),viewDialog);
            }

            @Override
            public void onFailure(Call<JsonObject> call, Throwable t) {
                Error(t);
            }
        });
    }

}
